jQuery(document).ready(function(){
	var $form = jQuery('form[name="informationEdit"]');
	if (jQuery('input[name="state"]', $form).val() != "DEL"){
	    KE.show({
	        id : 'content1',
	        width : '100%',
	        height : '500px',
	        skinType: 'tinymce',
	        resizeMode : 0,
	        cssPath : '../commons/kindeditor/kindeditor.css',
	        afterCreate : iframeAutoFit
	    });
	}
	// 绑定按钮事件
	// 页面[保存]按钮
	jQuery('#btnSave').click(
		function() {
			saveInfo($form);
		}
	);
	// 页面[发布]按钮
    jQuery('#btnPublish').click(
		function() {
			if(confirm('是否确定要发布新闻？')){
				jQuery('input[name="state"]', $form).val('PUBLISHED');
				saveInfo($form);
			}
		}
	);
    // 页面[预览]按钮
    jQuery('#btnPreview').click(
		function() {
			KE.util.setData('content1');
			jQuery('input[name="event"]', $form).val('showReference');
			$form.attr('target', '_blank');
			$form.submit();
			$form.attr('target', '_self');
		}
	);
	// 页面[返回]按钮
	jQuery('#btnBack').click(
		function() {
			var state = jQuery('input[name="state"]', $form).val();
			if (state=="" || state==null){
				state = "PUBLISHED";
			}
			location.href="informationList.shtml?ec_f_state="+ state +"&ec_f_catalog="+jQuery('input[name="catalog"]').val();
		}
	);
	// 页面[删除]按钮
	jQuery('#btnDel').click(
		function() {
			if(confirm('是否确定要删除新闻？')){
				$form.attr('action', 'informationList.shtml');
				jQuery('input[name="editState"]', $form).val('DEL');
				jQuery('input[name="event"]', $form).val('updateStateByItem');
				$form.submit();
			}
		}
	);
	// 页面[继续新增]按钮
	jQuery('#btnAdd').click(
		function() {
			if(confirm('数据是否已保存？')){
				location.href="informationEdit.shtml?catalog="+jQuery('input[name="catalog"]').val();
			}
		}
	);
	// 页面[彻底删除]按钮
	jQuery('#btnComplete').click(
		function() {
			if(confirm('是否确定彻底要删除新闻，删除后无法恢复？')){
				$form.attr('action', 'informationList.shtml');
				jQuery('input[name="event"]', $form).val('deleteItem');
				$form.submit();
			}
		}
	);
	// 页面[恢复]按钮
	jQuery('#btnRestore').click(
		function() {
			if(confirm('是否确定要恢复已删除的新闻，恢复到草稿状态？')){
				$form.attr('action', 'informationList.shtml');
				jQuery('input[name="editState"]', $form).val('DRAFT');
				jQuery('input[name="event"]', $form).val('updateStateByItem');
				$form.submit();
			}
		}
	);
	// 页面[测试]按钮
	jQuery('#btnSetIndexShow').click(
		function() {
			var disCont = jQuery("#photoList",$form).val();
			if (disCont != ""){
				disCont = disCont.toString();
				var ind = disCont.indexOf('/commons/showImg.shtml');
				disCont = disCont.substr(ind);
				jQuery('input[name="display"]', $form).val(disCont);
			}
		}
	);
	jQuery("#photoList").bind("change", function(event){
		var url = jQuery(this).val();
		jQuery('#showPhoto', $form).attr("src",url);
	});
});

function saveInfo($form){
	KE.util.setData('content1');
	if (validateRequiredField($form)){
		jQuery('input[name="event"]', $form).val('save');
		$form.submit();
	}
}

function changeImgInfo(photoId,url,title){
	var $form = jQuery('form[name="informationEdit"]');
	if (title ==""){
		title = "未命名图片";
	}
	jQuery("#photoList",$form).append("<option value='"+ url + "'>" + title + "</option>");
	var photoIds = jQuery('input[name="photoIds"]', $form).val();
	if (photoIds != "" || photoIds != null){
		photoIds = photoIds + ",";
	}
	photoIds = photoIds + photoId;
	jQuery('input[name="photoIds"]', $form).val(photoIds);
}
//-->